package pattern.Singleton_P;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ResourceBundle;

/**
 * Created by dycong on 2017/3/20.
 *TODO 枚举的构造方法里进行的单例的初始化，通过枚举构造了其他类的单例模式:非正常使用方式！！！
 */
public enum Singleton_Emun {
    INSTANCE;
    private ComboPooledDataSource comboPooledDataSource = null;

    private Singleton_Emun() {
        try {
            ResourceBundle rs = ResourceBundle.getBundle("jdbc");
            comboPooledDataSource = new ComboPooledDataSource();
            comboPooledDataSource.setDriverClass(rs.getString("driverClass"));
            comboPooledDataSource.setJdbcUrl(rs.getString("jdbcUrl"));
            comboPooledDataSource.setUser(rs.getString("user"));
            comboPooledDataSource.setPassword(rs.getString("password"));
            comboPooledDataSource.setMaxPoolSize(Integer.parseInt(rs.getString("maxPoolSize")));
            comboPooledDataSource.setMinPoolSize(Integer.parseInt(rs.getString("minPoolSize")));
            System.out.println("-----调用了构造方法------");
            ;
        }catch (Exception e){

        }
    }

    public Connection getConnection()throws SQLException{
        return comboPooledDataSource.getConnection();
    }
}
